package com.hex.ds.hdrs.period.job.converter;

import com.hex.ds.hdrs.common.constant.Const;
import com.hex.ds.hdrs.common.utils.BaseUtil;
import com.hex.ds.hdrs.common.utils.HdrsDateUtil;
import com.hex.ds.hdrs.period.job.dto.PeriodJobDefDto;
import com.hex.ds.hdrs.period.job.dto.PeriodJobTaskDto;
import com.hex.ds.hdrs.period.job.po.PeriodJobDef;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;

@Mapper(componentModel = "spring", imports = {BaseUtil.class, HdrsDateUtil.class, Const.class})
public interface IPeriodJobDefConverter {

    @Mappings({
            @Mapping(target = "pkId", expression = "java(BaseUtil.getPkId())"),
    })
    PeriodJobDefDto toPeriodJobDefDto(PeriodJobTaskDto periodJobTaskDto, String batchTag, String appCode);

    @Mappings({
            @Mapping(target = "pkId", expression = "java(BaseUtil.getPkId())"),
            @Mapping(target = "crtTs", expression = "java(HdrsDateUtil.getCurrentTime())"),
            @Mapping(target = "crtUser", expression = "java(BaseUtil.getUserId())"),
            @Mapping(target = "upTs", expression = "java(HdrsDateUtil.getCurrentTime())"),
            @Mapping(target = "upUser", expression = "java(BaseUtil.getUserId())"),
            @Mapping(target = "jobStatus", expression = "java(periodJobDefDto.getJobStatus() != null ? periodJobDefDto.getJobStatus() : Const.UNPUBLISHED)")
    })
    PeriodJobDef toPeriodJobDefForAdd(PeriodJobDefDto periodJobDefDto);

    @Mappings({
            @Mapping(target = "upTs", expression = "java(HdrsDateUtil.getCurrentTime())"),
            @Mapping(target = "upUser", expression = "java(BaseUtil.getUserId())")
    })
    PeriodJobDef toPeriodJobDefForModify(PeriodJobDefDto periodJobDefDto);

    PeriodJobDef toPeriodJobDefForQuery(PeriodJobDefDto periodJobDefDto);
}
